package com.study.zjh.ioswheeldemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.study.zjh.ioswheeldemo.bean.PayBean;
import com.study.zjh.ioswheeldemo.bean.RuleBean;
import com.study.zjh.ioswheeldemo.view.SelectorSingleWindow;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private TextView tv;
    private TextView tv2;
    private SelectorSingleWindow selectorSingleWindow;
    private List<PayBean> payBeans = new ArrayList<>();
    private List<RuleBean> ruleBeans = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv=(TextView)findViewById(R.id.tv);
        tv2=(TextView)findViewById(R.id.tv2);
        payBeans.add(new PayBean(1,"银联支付"));
        payBeans.add(new PayBean(2,"微信支付"));
        payBeans.add(new PayBean(3,"支付报支付"));
        payBeans.add(new PayBean(4,"转账支付"));

        ruleBeans.add(new RuleBean(1,"老师"));
        ruleBeans.add(new RuleBean(2,"学生"));
        ruleBeans.add(new RuleBean(3,"科学家"));
        ruleBeans.add(new RuleBean(4,"工程师"));
        ruleBeans.add(new RuleBean(5,"职员"));
        ruleBeans.add(new RuleBean(6,"军人"));
        ruleBeans.add(new RuleBean(7,"主席"));
        ruleBeans.add(new RuleBean(8,"农民"));

        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showPopupWindow();
            }
        });
        tv2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showPopupWindow2();
            }
        });
    }

    private void showPopupWindow(){
        if(selectorSingleWindow!=null){
            selectorSingleWindow.dissPopupWindow();
            selectorSingleWindow=null;
        }
        selectorSingleWindow = new SelectorSingleWindow(this,payBeans);
        try {
            selectorSingleWindow.showSelectPopupWind();
            selectorSingleWindow.setOnChancedDayListener(new SelectorSingleWindow.OnChancedDayListener() {
                @Override
                public void onSureClick(String str1, int code) {
                    tv.setText(code+str1);
                }

                @Override
                public void onCancleClick() {

                }
            });
        } catch (IllegalAccessException e) {
            Toast.makeText(MainActivity.this,"初始化数据失败！",Toast.LENGTH_SHORT).show();
            e.printStackTrace();
        }
    }

    private void showPopupWindow2(){
        if(selectorSingleWindow!=null){
            selectorSingleWindow.dissPopupWindow();
            selectorSingleWindow=null;
        }
        selectorSingleWindow = new SelectorSingleWindow(this,ruleBeans);
        try {
            selectorSingleWindow.showSelectPopupWind();
            selectorSingleWindow.setOnChancedDayListener(new SelectorSingleWindow.OnChancedDayListener() {
                @Override
                public void onSureClick(String str1, int code) {
                    tv2.setText(code+str1);
                }

                @Override
                public void onCancleClick() {

                }
            });
        } catch (IllegalAccessException e) {
            Toast.makeText(MainActivity.this,"初始化数据失败！",Toast.LENGTH_SHORT).show();
            e.printStackTrace();
        }
    }
}
